package com.hgkj.cloud.base.scheme.table;

import com.hgkj.cloud.base.scheme.ClsAnswerRequest;
import com.hgkj.cloud.base.scheme.ClsAnswerResult;
import com.hgkj.cloud.base.scheme.ClsScore;

import java.util.Map;

/**
 *
 */
public class Table126 extends AbstractTable implements TableCalculate{
    String code = "";

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public ClsAnswerResult calc(ClsAnswerRequest answer) {
        return null;
    }

    @Override
    public String[] report(Map map) {
        return null;
    }
    
	// 一百二十六、小学生心理健康综合测量(Xxxljkzh)，共80题，8个因子，3个选项
	private static ClsAnswerResult GetXxxljkzhFactorScore(ClsAnswerRequest answer) {
		// 1学习障碍，2情绪障碍，3性格缺陷，4社会适应障碍，5品德缺陷，6不良习惯，7行为障碍，8特种障碍
		ClsAnswerResult result = new ClsAnswerResult();
		result.setMessage("");
		result.setType(answer.getType());
		result.setUuid(answer.getUuid());
		try {
			// 1正确题数
			int MAX_NUM = 80;

			int intI;
			String[] strAnswer_c = answer.getAnswer().split(g_sChar);
			if (strAnswer_c.length > 1) {
				for (intI = 1; intI < strAnswer_c.length; intI++) {
					strAnswer_c[intI] = strAnswer_c[intI].trim();
				}
			}

			String[] strChildAnswerA = strAnswer_c[0].toString().split(g_nChar);

			if (strChildAnswerA.length != MAX_NUM) {
				result.setMessage("答案数量不符！");
				return result;
			}

			int i, j;

			// 共1组，2,1,0
			int[] intNumberA = { 10, 20, 30, 40, 50, 60, 70, 80 };

			float[] vFactorA = new float[8]; // 实际为8个因子
			String[] vAppraiseA = new String[8]; // 诊断结果

			for (i = 0; i < vFactorA.length; i++) {
				vFactorA[i] = 0;
				vAppraiseA[i] = "";
			}

			int intIndex = 0;
			for (i = 0; i < strChildAnswerA.length; i++) {
				if (i == intNumberA[intIndex]) {
					intIndex += 1;
				}
				vFactorA[intIndex] += 3 - Integer.valueOf(strChildAnswerA[i]);
			}

			// 诊断结果
			String[] arrApp = { "异常，需要接受心理辅导。", "可能异常，需要引起关注。", "正常。" };
			int[] arrNum = { 10, 3 };
			for (i = 0; i < vFactorA.length; i++) {
				vAppraiseA[i] = arrApp[arrApp.length - 1];
				for (j = 0; j < arrNum.length; j++) {
					if (vFactorA[i] >= arrNum[j]) {
						vAppraiseA[i] = arrApp[j];
						break;
					}
				}
			}

			ClsScore.Xxxljkzh xxxljkzh = new ClsScore.Xxxljkzh();

			xxxljkzh.setXx_o(vFactorA[0]);
			xxxljkzh.setXx_a(vAppraiseA[0]);

			xxxljkzh.setQx_o(vFactorA[1]);
			xxxljkzh.setQx_a(vAppraiseA[1]);

			xxxljkzh.setXg_o(vFactorA[2]);
			xxxljkzh.setXg_a(vAppraiseA[2]);

			xxxljkzh.setSh_o(vFactorA[3]);
			xxxljkzh.setSh_a(vAppraiseA[3]);

			xxxljkzh.setPd_o(vFactorA[4]);
			xxxljkzh.setPd_a(vAppraiseA[4]);

			xxxljkzh.setBl_o(vFactorA[5]);
			xxxljkzh.setBl_a(vAppraiseA[5]);

			xxxljkzh.setXw_o(vFactorA[6]);
			xxxljkzh.setXw_a(vAppraiseA[6]);

			xxxljkzh.setTz_o(vFactorA[7]);
			xxxljkzh.setTz_a(vAppraiseA[7]);

			result.setObject(xxxljkzh);
			return result;
		} catch (ArithmeticException e) {
			result.setMessage(e.toString());
			return result;
		}
	}

}
